using System;
using System.Collections.Generic;
using System.Text;

namespace My.IdlConverter.Registration
{
    public static class AddinRegistrationUtil
    {
        public static string DefaultIdlConverterVersion()
        {
            return "1.0";
        }

        public static string DefaultEmptyField()
        {
            return "unknown";
        }

        public static string RegularString(string prop,int length)
        {
            string ret = prop.Trim();
            if (ret.Length <= length)
                return ret;
            return ret.Substring(0, length);
        }

        public static string FormatRegTime(DateTime regTime)
        {
            return regTime.ToString("d");
        }

        public static void RegularAddinEntity(Addin addin)
        {
            addin.ID = RegularString(addin.ID, 50);
            addin.Name = RegularString(addin.Name, 50);
            addin.Company = RegularString(addin.Company, 50);
            addin.Code = RegularString(addin.Code, 256);
            addin.Description = RegularString(addin.Description, 256);
            addin.Version = RegularString(addin.Version, 50);
            addin.IdlConverterVersion = RegularString(addin.IdlConverterVersion, 50);
            addin.RegistrationTime = RegularString(addin.RegistrationTime, 50);
            addin.Developer = RegularString(addin.Developer, 50);
            addin.AddinFrom = RegularString(addin.AddinFrom, 50);
            addin.Memo = RegularString(addin.Memo, 256);
        }
    }
}
